home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The 640 MEG Shareware Studio 2
/
The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO
/
utility
/
scrub.zip
/
SCRUB.C
next >
Wrap
C/C++ Source or Header
|
1992-01-08
|
1KB
|
58 lines
#include <stdio.h>
void main (argc, argv)
int argc;
char *argv[];
{
FILE *text_in, *text_out;
char ch, name[16];
tmpnam(name);
if (argc < 3){
puts ("SCRUB removes the unwanted character from your file.\n\n");
puts ("Syntax: SCRUB <file> <ASCII code for char>\n\nPlease retry.\n");
exit(0);
}
if (atoi (argv[2]) == 0){
puts ("You must enter an ASCII code other than 0.");
exit();
}
if (rename (argv[1], name) != 0){
perror ("rename");
}
if ((text_in = fopen (name, "r")) == NULL){
puts ("Error opening file\n");
exit(0);
}
if ((text_out = fopen (argv[1], "w"))==NULL){
puts ("Error opening outfile");
exit(0);
}
while (!feof (text_in)){
ch=getc(text_in);
if (ch != atoi (argv[2])){ /* Is it NOT the char? */
putc (ch, text_out); /* If not, pass it out */
}
else{ /* Otherwise, output */
putc (' ', text_out); /* a SPACE */
}
}
if (fclose(text_in)) puts ("Error closing infile\n");
if (fclose(text_out)) puts ("Error closing tempfile\n");
if (unlink (name) != 0){
perror ("unlink");
}
puts ("Done - thank you for using SCRUB!\n");
exit(0);
}